package cn.xianyang.controller;

import cn.xianyang.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 浏览器来调用
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    public User getById(@PathVariable("id") long id){
        //拼接要调用的服务controller地址   写死了
        //String url = "http://localhost:3000/user/getById/"+id;
        //使用ribbon的负载均衡能力去选择user-server去调用
        //通过应用名去调用user-server
        String url = "http://user-server/user/getById/"+id;
        return restTemplate.getForObject(url,User.class);
    }
}
